<template>
  <div id="cornerComment" v-if="dialogVisible">
    <div class="cornerComment-in">
      <div class="cornerComment-in-title">
        <span>全日健康表格总览</span>
        <span class="el-icon-circle-close close-Btn-line" @click="closePOpup"></span>
      </div>
      <div class="commentBody">
        <el-table
            ref="multipleTable"
            :data="arryList"
            :stripe="tableoption.tableStripe"
            :border="tableoption.tableBorder"
            tooltip-effect="dark"
            style="width: 100%"
            header-cell-class-name="table-text-c"
            cell-class-name="table-text-c">
          <el-table-column
              prop="name"
              label="表格名称"
              width="230">
          </el-table-column>
          <el-table-column
              label="筛选条件">
            <template slot-scope="scope">
              <div class="checklist">
                <el-date-picker
                    v-if="scope.row.needQuery.indexOf('regionTime')!==-1"
                    v-model="scope.row.query.regionTime"
                    type="daterange"
                    range-separator="至"
                    start-placeholder="开始日期"
                    end-placeholder="结束日期"
                    format="yyyy-MM-dd"
                    value-format="yyyy-MM-dd"
                    size="small"
                    class="mr-10">
                </el-date-picker>
                <el-date-picker
                    v-if="scope.row.needQuery.indexOf('start_time')!==-1"
                    v-model="scope.row.query.start_time"
                    type="date"
                    placeholder="选择日期"
                    value-format="yyyy-MM-dd"
                    size="small"
                    class="w-140"
                    :picker-options="pickerOptions1"
                ></el-date-picker>
                <el-date-picker
                    v-if="scope.row.needQuery.indexOf('month')!==-1"
                    v-model="scope.row.query.month"
                    size="small"
                    type="month"
                    format="yyyyMM"
                    value-format="yyyyMM"
                    style="width: 150px;"
                    class="mr-10"
                    placeholder="选择月份">
                </el-date-picker>
                <component
                    v-bind:is="item.propertyType"
                    :property.sync="item"
                    v-for="(item, index) in scope.row.getPower"
                    :key="index"
                    @updateVal="updateVal($event, scope.$index)"
                ></component>
              </div>
            </template>
          </el-table-column>
          <el-table-column
              label="操作"
              width="130"
              align="center">
            <template slot-scope="scope">
              <excelDownLoadBtn :disabledState="disabledState(scope.row)"
                                :downloadOption="scope.row"></excelDownLoadBtn>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div class="cornerComment-in-footer">
        <el-button @click.native="closePOpup" size="small">返回</el-button>
      </div>
    </div>
  </div>
</template>

<script>
import {tableoption} from '@/utils/util.js'
import dataDownLine from "./dataDownLine";

export default {
  props: ['visible'],
  components: {},
  data() {
    return {
      dialogVisible: false,
      arryList: JSON.parse(JSON.stringify(dataDownLine.data)),
      tableoption: tableoption,
      pickerOptions1: {
        disabledDate(time) {
          return time.getTime() > Date.now() //  - 8.64e7
        }
      },
    }
  },
  watch: {
    visible() {
      this.dialogVisible = this.visible
      if (this.visible) {
        this.arryList = JSON.parse(JSON.stringify(dataDownLine.data))
      }
    }
  },
  created() {

  },
  methods: {
    // 关闭弹窗
    closePOpup() {
      this.$emit('update:visible', false)
    },
    getJson(option) {
      return JSON.parse(JSON.stringify(option))
    },
    disabledState(row) {
      let state = false
      for (let item of row.disabled) {
        if (!row.query[item]) {
          state = true
        }
        if(item==='regionTime'){
          if(!row.query[item] || (row.query[item] && !row.query[item].length)){
            state = true
          }
        }
      }
      return state
    },
    updateVal(option, index) {
      // console.log('变更数据收到的数据内容：', option, index, this.arryList)
      if (option.input) {
        this.arryList[index].query[option['input'].name] = option['input'].valueText
      } else if (option.select) {
        for (let i in option.select) {
          if (option.select[i].name) {
            this.arryList[index].query[option.select[i].name] = option.select[i].valueText
          } else {
            this.arryList[index].query[option.select[i - 1].name] = option.select[i].valueText ? option.select[i].valueText : option.select[i - 1].valueText
          }
        }
      }
      if (option.nameOption) {
        this.arryList[index].className = option.nameOption
      }
    },
  },
  mounted() {
  }
}
</script>
<style scoped>
#cornerComment {
  height: 100vh;
  width: 100%;
  position: fixed;
  top: 0;
  left: 0;
  background: rgba(0, 0, 0, .5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9;
}

.cornerComment-in {
  width: 80%;
  height: 70%;
  background: #fff;
  display: flex;
  flex-direction: column;
  border-radius: 5px;
}

.cornerComment-in-title {
  height: 50px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid #ddd;
  font-size: 24px;
}

.cornerComment-in-title span {
  padding: 0 10px;
}

.cornerComment-in-title span:first-child {
  flex: 1;
  font-size: 16px;
}

.cornerComment-in-footer {
  height: 50px;
  border-top: 1px solid #ddd;
  display: flex;
  align-items: center;
  padding: 0 10px;
  justify-content: center;
}

.commentBody {
  padding: 10px;
  flex: 1;
  overflow-y: auto;
}

.close-Btn-line {
  cursor: pointer;
}

.resruitment-title {
  padding: 5px 0;
  border-bottom: 2px solid #abd3f3;
  margin-bottom: 20px;
}

.el-radio {
  margin-right: 20px;
}

.jobTime {
  display: flex;
  align-items: center;
}

.jobTime span {
  padding: 0 10px;
}

.checklist {
  display: flex;
  align-items: center;
}
</style>


